package com.xxx.Steam;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/26  15:43
 * @Copyright
 */
public class StreamDome {
    public static void main(String[] args) {
//        M1();
        ArrayList<Student> students = new ArrayList<>();
        students.add(new Student("张三", 23, "男", 96));
        students.add(new Student("张1三", 33, "女", 82));
        students.add(new Student("张2三", 43, "男", 65));
        students.add(new Student("张3三", 53, "男", 64));
        students.add(new Student("张4三", 63, "女", 73));
        students.add(new Student("张5三", 73, "女", 66));
        students.add(new Student("张6三", 83, "女", 76));
        students.add(new Student("张7三", 93, "男", 86));
        Stream<Student> stream = students.stream();
//        stream.forEach(new Consumer<ArrayList<Student>>() {
//            @Override
//            public void accept(ArrayList<Student> students) {
//                System.out.println("students = " + students);
//            }
//        });
//        stream.forEach(student -> {
//            System.out.println("student = " + student.getName());
//
//        });
        //stream.forEach(System.out::println);
        stream.filter(student -> student.getName().startsWith("张")).forEach(System.out::println);
    }

    private static void M1() {
        ArrayList<String> strings = new ArrayList<>();//从集合中获取Stream流对象
        Stream<String> stream = strings.stream();//顺序流
        Stream<String> stream1 = strings.parallelStream();//并行流

        //从数组中获取Stream流对象
        int[] ints = {1, 2, 3, 4};
        IntStream stream2 = Arrays.stream(ints);

        //通过Stream的of()方法
        Stream<ArrayList<String>> strings1 = Stream.of(strings);
        Stream<Integer> integerStream = Stream.of(1, 2, 3, 6, 4);
        Stream<HashSet<String>> hashSetStream = Stream.of(new HashSet<String>());
    }
}
